<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <textarea name="" id="txt" cols="30" rows="10"></textarea>
        <button id="btn">按钮</button>

        <script>
            var btn=document.getElementById('btn');
            var txt=document.getElementById('txt');
            btn.onclick=function(){
                if(txt.value==''){
                    window.alert("请输入内容");
                }
                else{
                    //创建标签
                    var tag=document.createElement('h1');
                    //增加内容
                    tag.innerHTML=txt.value;
                    //追加标签 把tag追加到body内部
                    document.body.appendChild(tag);
                    //把值清空
                    txt.value='';
                }
            }
        </script>
    </body>
</html>